package eu.whowie.bluecontrol.server;

import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
	
	private Server server;
	private Logger logger = LoggerFactory.getLogger("MAIN");
	private int PORT=8080;

	private void startWebServer() {
		try {
			server = new Server();
			final Connector connector = new SelectChannelConnector();
			connector.setPort(PORT);
			server.setConnectors(new Connector[] { connector });

			WebAppContext webappcontext = new WebAppContext();
			webappcontext.setContextPath("");
			webappcontext.setWar("src/main/resources//WebContent");
			webappcontext.setClassLoader(Thread.currentThread()
					.getContextClassLoader());

			server.setHandler(webappcontext);

			server.start();

			server.join();

			logger.info("Jetty started, please go to http://localhost:" + PORT
					+ "/");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Main m = new Main();
		m.startWebServer();

	}

}
